package com.lagou.sqlSession;

import com.lagou.config.XmlConfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * SqlSessionFactoryBuilder,该类用于提供了一系列重载的build()方法，
 * 我们需要以主配置文件的输入流作为参数调用SqlSessionFactoryBuilder对象的bulid()方法，
 * 生成SqlSessionFactory对象
 *
 * @author YiYa
 * @since 2020-11-08 上午 09:22
 */
public class SqlSessionFactoryBuilder {
    /**
     * 1、使用dom4j解析配置文件，将解析出来的内容封装Configuration
     *  此时的Configuration对象已经包含了主配置类信息和SQL配置类信息
     * 2、创建SqlSessionFactory对象
     */
    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException {
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }

}
